<template>
  <div class="card">
    <div class="form">
    <h1 class="header">交友后台管理系统</h1>
      <el-form
        :model="userinfo"
        :rules="rules"
        ref="formRef"
        label-width="100px"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            type="text"
            v-model.number="userinfo.username"
            autocomplete="off"
          />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="text"
            v-model.number="userinfo.password"
            autocomplete="off"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  :disabled="isshow"  @click="submitForm"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {
        username: "",
        password: "",
      },
      num: 0,
      isshow: false,
    };
  },
  computed: {
    rules() {
      return {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 2, max: 7, message: "长度在 2 到 7 个字符" },
          { pattern: /^[\u4E00-\u9FA5]+$/, message: "用户名只能为中文" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 5, max: 25, message: "长度在 5 到 25个字符" },
          {pattern: /^(\w){5,25}$/, message: "只能输入5-25个字母、数字、下划线",},
        ],
      };
    },
  },

  methods: {
    //表单提交
    submitForm() {
      this.$refs["formRef"].validate( (valid) => {
        if (valid) {
          //验证成功
          this.$notify({
            title: "成功",
            message: "欢迎您，尊贵的殿下",
            type: "success",
          });
              this.$router.push('/admin');
        } else {
          this.$message.error("账号或密码不正确");
          this.num++;
          //   console.log(this.num);
          if (this.num > 3) {
            this.$message({
              showClose: true,
              message: "输入超过3次，请24小时之后再次输入",
              type: "error",
            });
            this.isshow = true;
            // console.log(this.isshow);
          }
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.card {
  width: 100%;
  height: 100vh;
  background: url("../../Img/02.png") no-repeat;
  background-size: cover;
  .form {
    width: 400px;
    height: 320px;
    border-radius: 15px;
    background-color: #464666;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .el-form {
      width: 300px;
      margin: 15px;
      margin-top: 40px;
    }
    .el-form-item__label {
      width: 85px;
    }
    .el-button--primary {
      margin-left: 60px;
    }
    .el-notification__content p {
      color: golden;
    }
    .header{
      text-align: center;
      font-size: 30px;
      font-weight: bold;
      margin-top: 40px;
      color:cadetblue;
    }
  }
}
</style>